﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Storage;

namespace ShaderLab
{
    class PointLight
    {

        #region Light Properties
        Vector3 position;
        public Vector3 Position
        {
            get { return position; }
            set {
                position = value;
                structPosition.SetValue(position);
            }
        }

        Color color;
        public Color Color
        {
            get { return color; }
            set {
                color = value;
                structColor.SetValue(color.ToVector3());
            }
        }

        float range;
        public float Range
        {
            get { return range; }
            set { 
                range = value;
                structRange.SetValue(range);
            }
        }

        float fallOff;
        public float FallOff
        {
            get { return fallOff; }
            set {
                fallOff = value;
                structFallOff.SetValue(fallOff);
            }
        }
        #endregion


        #region Effect
        Effect effect;

        EffectParameter structInstance;

        EffectParameter structPosition;

        EffectParameter structColor;

        EffectParameter structRange;

        EffectParameter structFallOff;
        #endregion


        #region Initialization
        public PointLight(Effect effect)
        {
            this.effect = effect;
            structInstance = effect.Parameters["PointLight"];
            structPosition = structInstance.StructureMembers["Position"];
            structColor = structInstance.StructureMembers["Color"];
            structRange = structInstance.StructureMembers["Range"];
            structFallOff = structInstance.StructureMembers["FallOff"];

            Position = Vector3.Zero;
            Range = 30f;
            FallOff = 2f;
            Color = Color.White;
        }
        #endregion


        public void UpdateLight()
        {
            structColor.SetValue(color.ToVector3());
            structFallOff.SetValue(fallOff);
            structPosition.SetValue(position);
            structRange.SetValue(range);
        }

    }
}
